/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ivanbiz.account;

import com.ivanbiz.generic.GenericDAOImpl;
import org.hibernate.Query;

/** 
 *
 * @author User
 */
public class AccountDAOImpl extends GenericDAOImpl implements AccountDAO {

    public boolean cekIsEmptyCard(String kode, String nama) throws Exception {
        Query query = getSessionFactory().getCurrentSession().createQuery("from AccountCard ac where ac.nama=:nama and ac.noCard=:kode");
        query.setString("nama", nama);
        query.setString("kode", kode);
        if (query.uniqueResult() != null) {
            return true;
        } else {
            return false;
        }
    }

    public boolean cekIsEmptyKode(String kode) throws Exception {
        Query query = getSessionFactory().getCurrentSession().createQuery("from Account a where a.kode=:kode");
        query.setString("kode", kode);
        if (query.uniqueResult() != null) {
            return true;
        } else {
            return false;
        }
    }

    public Account loadByUserId(long id) throws Exception {
        Query query = getSessionFactory().getCurrentSession().createQuery("from Account a where a.user.id=:id");
        query.setParameter("id", id);      
        return (Account) query.uniqueResult();
    }
}
